www.gusucode.com > 支持向量机工具箱 - LIBSVM OSU_SVM LS_SVM源码程序 > 支持向量机工具箱 - LIBSVM OSU_SVM LS_SVM\stprtool\linear\ctransf.m

    function [nalpha,NMI,varargin]=ctransf(alpha,theta,MI,I,SIGMA)
% CTRANSF adds one constant coordinate.
%  [nalpha,NMI,varargin]=ctransf(alpha,theta,MI,I,SIGMA)
%
% CTRANSF adds one constant coordinate to a training set so
%   that the original task of finding arbitrary placed hyperplane
%   becomes simpler. More precisely, the original task is to find
%   the vector alpha and the threshold theta (determine hyperplane)
%   for which holds
%           alpha' * x >= theta   for any x from the first class
%           alpha' * x < theta    for any x from the second class
%
%   After adding of one constant coordinate the original task
%   changes to equivalent one where the goal is to find nalpha
%   (hyperplane going through origin) for which holds
%           nalpha' * nx >= 0   for any nx from the first class
%           nalpha' * nx <  0   for any nx from the second class
%
% Input:
%   1. If input classes are finite point sets then use syntax
%      [nalpha,NX]=ctransf(alpha,theta,X,I)
%
%    where
%    alpha [Nx1] is a normal vector of the hyperplane in original space.
%    theta [1x1] is a threshold in original space.
%    X [NxM] is a matrix containing M points in N-dimensional
%       feature space. So that X=[x1,x2 ...xM] and xs are
%       column vectors.
%    I [1xM] is a vector of class labels for each point. In this
%       case possible value is 1 for first class or 2 for
%       second class.
%    nalpha [(N+1)x1] is transformed normal vector.
%    NX [NxM] is matrix of transformed points.
%
%   2. If input classes are described by normal mixtures then use
%      [nalpha,NMI,NSIGMA]=ctransf(alpha,theta,MI,I,SIGMA)
%
%    where
%    alpha [Nx1] is a normal vector of hyperplane in original space.
%    theta [1x1] is a threshold in original space.
%    MI [NxM] is a matrix containing M vectors of mean values in
%       N-dimensional space. Matrix MI=[mi1,mi2,...,miM]
%       contains column vectors.
%    SIGMA [Nx(M*N)] is a matrix containing M covariance matrices
%       so that SIGMA=[sigma1,sigma2,...sigmaM]. Individual
%       covariance matrices are of dimension N-by-N.
%    I [1xN] is a vector of class labels for each pair of parameters
%       [mi,sigma]. In this case, possible value is 1 for the first
%       class or 2 for the second class.
%    NMI [(N+1)xM] is matrix of transformed vectors of mean values.
%    NSIGMA [(N+1)x(M*(N+1))] is a matrix containing covariance
%       matrices.
%
% See also ICTRANSF.
%

% Statistical Pattern Recognition Toolbox, Vojtech Franc, Vaclav Hlavac
% (c) Czech Technical University Prague, http://cmp.felk.cvut.cz
% Written Vojtech Franc (diploma thesis) 24.10.1999
% Modifications
% 24. 6.00 V. Hlavac, comments polished.

D=size(MI,1);   % dimension
K=size(MI,2);   % number of MIs and SIGMAs

% transform alpha
if sum(alpha)==0 & theta==0,
   nalpha=zeros(D+1,1);
else
   nalpha=[alpha;-theta];
end

NMI=[];
NSIGMA=[];
for i=1:K,
   if I(i) == 1,
      NMI=[NMI,[MI(:,i);1]];
      if nargin >= 5,
         NSIGMA=[NSIGMA,[ [SIGMA(:,(i-1)*D+1:i*D),zeros(D,1)] ; zeros(1,D+1)]];
      end
   elseif I(i) == 2,
      NMI=[NMI,-[MI(:,i);1]];
      if nargin >= 5,
         NSIGMA=[NSIGMA,[ [SIGMA(:,(i-1)*D+1:i*D),zeros(D,1)] ; zeros(1,D+1)]];
      end
   end

end

if nargin >= 5,
   varargin=NSIGMA;
end